package com.yunfei.api.financialCalculator.service;
import com.yunfei.api.financialCalculator.param.RiQiCalParam;
import com.yunfei.api.financialCalculator.result.RiQiCalResult;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.ResultStatus;
import com.yunfei.enums.RiQiCalResultStatus;
import com.yunfei.procedure.RiQiCalProcedure;
import com.yunfei.utils.jdbc.AiiidbUtil;
import com.yunfei.utils.string.StringUtil;
import org.springframework.core.env.Environment;
//日期计算器
public class RiQiCalService {
    //日期计算器接口
    public static ResultModel cal(RiQiCalParam param, Environment env){
        ResultModel resultModel=new ResultModel();
        String cntTyp=param.getCntTyp();
        String strDate=param.getStrDate();
        String endDate=param.getEndDate();
        //参数校验
        if(StringUtil.isNullOrEmpty(cntTyp)){
            resultModel.setCode(RiQiCalResultStatus.cntTyp.getCode());
            resultModel.setMessage(RiQiCalResultStatus.cntTyp.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(strDate)){
            resultModel.setCode(RiQiCalResultStatus.strDate.getCode());
            resultModel.setMessage(RiQiCalResultStatus.strDate.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(endDate)){
            resultModel.setCode(RiQiCalResultStatus.endDate.getCode());
            resultModel.setMessage(RiQiCalResultStatus.endDate.getMessage());
            return resultModel;
        }
        //获取数据库连接
        AiiidbUtil aiiidbUtil=AiiidbUtil.getInstance(env);
        //调用处处过程
        RiQiCalResult result=new RiQiCalProcedure().callProcedure(aiiidbUtil,param);
        resultModel.setData(result);
        resultModel.setCode(ResultStatus.SUCCESS.getCode());
        resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        return resultModel;
    }
}
